package com.carkeeper.serve.controller;


import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.serve.service.ServeTypeService;
import com.carkeeper.pojo.ServeType;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/serveType")
public class ServeTypeController {

    @Autowired
    private ServeTypeService serveTypeService;

    /**
     * 分页条件查询
     * @param map
     * @return
     */
    @ApiOperation("分页条件查询")
    @PostMapping("/findPage")
    public Result<PageInfo<ServeType>> findPage(@RequestBody Map map){
        PageInfo<ServeType> serveTypeInfo = serveTypeService.findPage(map);
        return new Result<>(true, StatusCode.OK,"",serveTypeInfo);
    }

    /**
     * 增加服务分类
     * @param serveType
     * @return
     */
    @ApiOperation("增加服务分类")
    @PutMapping("/addServeType")
    public Result addServeType(@RequestBody ServeType serveType){
        serveTypeService.addServeType(serveType);
        return new Result(true, StatusCode.OK,"");
    }

    /**
     * 根据id查询服务分类信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询服务分类信息")
    @GetMapping("/findById/{id}")
    public Result<ServeType> findById(@PathVariable("id") String id){
        ServeType serveType = serveTypeService.findById(id);
        return new Result<ServeType>(true,StatusCode.OK,"",serveType);
    }

    /**
     * 修改服务分类
     * @param serveType
     * @return
     */
    @ApiOperation("修改服务分类")
    @PutMapping("/updateServeType")
    public Result updateServeType(@RequestBody ServeType serveType){
        serveTypeService.updateServeType(serveType);
        return new Result(true, StatusCode.OK,"");
    }

    /**
     * 删除服务分类
     * @param id
     * @return
     */
    @ApiOperation("删除服务分类")
    @DeleteMapping("/deleteServeType/{id}")
    public Result deleteServeType(@PathVariable("id") String id){
        serveTypeService.deleteServeType(id);
        return new Result(true,StatusCode.OK,"");
    }

    /**
     * 级别列表展示
     * @return
     */
    @ApiOperation("级别列表展示")
    @GetMapping("/findByLevel")
    public Result<List> findByLevel(){
        List list = serveTypeService.findByLevel();
        return new Result<>(true,StatusCode.OK,"",list);
    }
}
